import 'package:favorcate/core/viewmodel/filter_view_model.dart';
import 'package:favorcate/ui/shared/size_fit.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class JKFilterContent extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        buildChoiceTitle(context),
        buildChoiceSelect(context)
      ],
    );
  }

  // 展示你的选择
  Widget buildChoiceTitle(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(16.px),
      alignment: Alignment.center,
      child: Text('展示你的选择', style: Theme.of(context).textTheme.headline3.copyWith(fontWeight: FontWeight.bold),),
    );
  }

  Widget buildChoiceSelect(BuildContext context) {
    return Expanded(
      child: Consumer<JKFilterViewModel>(
        builder: (ctx, filterVM, child) {
          return ListView(
            children: [
              buildListTitle(context, '无谷蛋白', '展示无谷蛋白食物', filterVM.isGlutenFree, (value) {
                filterVM.isGlutenFree = value;
              }),
              buildListTitle(context, '不含乳糖', '展示不含乳糖食物', filterVM.isLactoseFree, (value) {
                filterVM.isLactoseFree = value;
              }),
              buildListTitle(context, '普通素食者', '展示普通素食食物', filterVM.isVegetarian, (value) {
                filterVM.isVegetarian = value;
              }),
              buildListTitle(context, '严格素食者', '展示严格素食相关食物', filterVM.isVegan, (value) {
                filterVM.isVegan = value;
              }),
            ],
          );
        },
      )
    );
  }
  
  Widget buildListTitle(BuildContext context, String title, String subtitle, bool value, Function action) {
    return ListTile(
      title: Text(title),
      subtitle: Text(subtitle),
      trailing: Switch(value: value, onChanged: action),
    );
  }
}
